package com.hqyj.css.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hqyj.css.pojo.HqyjUser;
import com.hqyj.css.service.UserService;

@Controller
public class LoginController {
	@Autowired
	UserService us;
	@RequestMapping("toLogin.cs")
	public String toLogin() {
		return "login";
	}
	@RequestMapping("login.cs")
	public String login(String username,String pwd,HttpServletRequest request,
			HttpServletResponse response) {
		List<HqyjUser> lis = us.listUser();
		for(int i= 0;i < lis.size();i++) {
			HqyjUser u = lis.get(i);
			if(u.getUserName().equals(username)&&u.getUserPassword().equals(pwd)) {
				HttpSession session = request.getSession();
				List<String> li = new ArrayList<>();
				li.add("addStu.cs");
				li.add("delStu.cs");
				li.add("updateStu.cs");
				li.add("listStu.cs");
				li.add("toAddStu.cs");
				li.add("addClass.cs");
				li.add("delClass.cs");
				li.add("updateClass.cs");
				li.add("listClass.cs");
				li.add("toAddClass.cs");
				session.setAttribute("urls", li);
				return "redirect:toAddClass.cs";
				
			}
		}
		return "login";
	}
	@RequestMapping("out.cs")
	public String out(HttpServletRequest request) {
		HttpSession session = request.getSession();
		session.invalidate();
		return "redirect:login.cs";
	}

}
